<template>
  <div class="full-height p-a-mini bg-white">
    <BKTable
      :columns="columns"
      :data="tableData"
    />
  </div>
</template>

<script>
import request from '@/utils/request'

export default {
  name: 'Online',
  data () {
    return {
      columns: [
        { title: '用户名', field: 'userName', width: 100 },
        { title: '昵称', field: 'nickName', width: 100 },
        { title: '部门', field: 'deptName' },
        { title: '登录时间', field: 'loginTime', width: 160, formatter: ({ cellValue }) => this.$utils.createDate(cellValue).format('YYYY-MM-DD HH:mm:ss') },
        { title: '失效时间', field: 'expireTime', width: 160, formatter: ({ cellValue }) => this.$utils.createDate(cellValue).format('YYYY-MM-DD HH:mm:ss') },
        { title: '登录位置', field: 'loginLocation' },
        { title: 'IP', field: 'ipaddr', width: 100 },
        { title: '操作系统', field: 'os', width: 100 },
        { title: '浏览器', field: 'browser', width: 100 },
        { title: 'token', field: 'tokenId' }
      ],
      tableData: []
    }
  },
  created () {
    request.get('/online').then((data) => {
      this.tableData = [...new Map(data.map(item => [item.userName, item])).values()]
    })
  }
}
</script>

<style lang="scss" scoped>
.table-card {
  height: 100%;

  ::v-deep {
    .el-card__body {
      height: 100%;
    }
  }
}

</style>
